//
//  WMEArticleFirstCollectionViewCell.m
//  everyDay_duiTang
//
//  Created by 恩叔 on 16/3/5.
//  Copyright © 2016年 enshu. All rights reserved.
//

#import "WMEArticleFirstCollectionViewCell.h"
#import "UIColor+Hex.h"
#import <Masonry.h>
#import <UIImageView+WebCache.h>

@interface WMEArticleFirstCollectionViewCell ()
@property (nonatomic, retain)UIImageView *avatar;
@property (nonatomic, retain)UILabel *name;
@property (nonatomic, retain)UILabel *title;
@property (nonatomic, retain)UILabel *line;
@property (nonatomic, retain)UILabel *categoryGroupName;
@end

@implementation WMEArticleFirstCollectionViewCell

- (void)dealloc
{
    [_avatar release];
    [_name release];
    [_title release];
    [_line release];
    [_categoryGroupName release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.contentView.backgroundColor = [UIColor whiteColor];
        //添加阴影
        self.contentView.layer.shadowOffset = CGSizeMake(0.1, 0.1);
        self.contentView.layer.shadowOpacity = 0.3;
        self.contentView.layer.shadowRadius = 1;
        
        self.avatar = [[UIImageView alloc] init];
//        _avatar.backgroundColor = [UIColor redColor];
        _avatar.layer.cornerRadius = 20;
        _avatar.clipsToBounds = YES;
        [self.contentView addSubview:_avatar];
        [_avatar release];
        
        self.name = [[UILabel alloc] init];
//        _name.backgroundColor = [UIColor yellowColor];
        _name.font = [UIFont boldSystemFontOfSize:17];
        _name.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:_name];
        [_name release];
        
        self.title = [[UILabel alloc] init];
//        _title.backgroundColor = [UIColor purpleColor];
        _title.font = [UIFont systemFontOfSize:13];
        _title.textAlignment = NSTextAlignmentCenter;
        _title.textColor = [UIColor lightGrayColor];
        [self.contentView addSubview:_title];
        [_title release];
        
        self.line = [[UILabel alloc] init];
        _line.backgroundColor = [UIColor lightGrayColor];
        [self.contentView addSubview:_line];
        [_line release];
        
        self.categoryGroupName = [[UILabel alloc] init];
//        _categoryGroupName.backgroundColor = [UIColor orangeColor];
        _categoryGroupName.textAlignment = NSTextAlignmentCenter;
        _categoryGroupName.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:_categoryGroupName];
        [_categoryGroupName release];
    }
    return self;
}

- (void)setModel:(WMEArticleModel *)model
{
    if (_model != model) {
        [_model release];
        _model = [model retain];
        [_avatar sd_setImageWithURL:[NSURL URLWithString:_model.authorAvatar]];
        _name.text = _model.authorName;
        _title.text = _model.articleTitle;
        _categoryGroupName.text = _model.articleCategoryGroupName;
        _categoryGroupName.textColor = [UIColor colorWithHexString:_model.articleCategoryGroupColor];
    }
}

- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes
{
    [super applyLayoutAttributes:layoutAttributes];
    __block __typeof(&*self)blockself = self;
    [_avatar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(40, 40));
        make.top.equalTo(blockself.mas_top).with.offset(10);
        make.centerX.mas_equalTo(blockself.mas_centerX);
    }];
    
    [_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(blockself.mas_left).with.offset(20);
        make.right.equalTo(blockself.mas_right).with.offset(-20);
        make.centerY.mas_equalTo(blockself.mas_centerY);
        make.height.equalTo(@0.3);
    }];
    
    [_name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(blockself.mas_left).with.offset(5);
        make.right.equalTo(blockself.mas_right).with.offset(-5);
        make.top.equalTo(_avatar.mas_bottom).with.offset(5);
        make.bottom.equalTo(_line.mas_top).with.offset(-5);
    }];
    
    [_title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(blockself.mas_left).with.offset(15);
        make.right.equalTo(blockself.mas_right).with.offset(-15);
        make.top.equalTo(_line.mas_bottom).with.offset(5);
        make.height.equalTo(@((self.contentView.frame.size.height / 2 - 15) /2));
    }];
    
    [_categoryGroupName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(blockself.mas_left).with.offset(5);
        make.right.equalTo(blockself.mas_right).with.offset(-5);
        make.top.equalTo(_title.mas_bottom).with.offset(10);
        make.bottom.equalTo(blockself.mas_bottom).with.offset(-5);
    }];
}

//[self.view setBackgroundColor:[self getColor:@"FF0000"]];


@end
